
/*

DEPENDENCIES:
-------------
ext.for_each
-------------


IN THIS FILE:
-------------
ext.swap_class
-------------

*/

Gimme.ext.swap_class = function(_oldClass, _newClass)
{
	// if _newClass is '$1' it means we're actually just removing _oldClass (and not replacing it with anything)
	// however, if _newClass is anything other than $1, we need to pad it with spaces 
	if (_newClass !== '$1')
	{
		_newClass = ' ' + _newClass + ' ';
	}
	
	var classes = _oldClass.split(/\s+/);
	
	this.for_each(function(_elem)
	{
		var tmpClass = _elem.className;
		
		Gimme(classes).for_each(function(_className)
		{
			var pattern = new RegExp('(^| )' + _className + '( |$)');
			tmpClass = tmpClass.replace(pattern, _newClass);
		});
		
		// TODO: was this really needed?  Can we get away with just trimming?
		// _elem.className = normalize(tmpClass);
		_elem.className = tmpClass.replace(/^\s+|\s+$/g, '');			
	});
	
	return this;
};
//[AltSyntax]Gimme.ext.swapClass = Gimme.ext.swap_class;